//
//  TableViewThreeController.m
//  Advertisement
//
//  Created by mac on 16/4/5.
//  Copyright © 2016年 Appcoda. All rights reserved.
//

#import "TableViewThreeController.h"
#import "netWork.h"
#import "MAin.h"
@interface TableViewThreeController ()

@end

@implementation TableViewThreeController

- (void)viewDidLoad {
    [super viewDidLoad];
     self.title = self.myTitle;
    _tableViewThree = [[UITableView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
    _tableViewThree.delegate = self;
    _tableViewThree.dataSource = self;
    _tableViewThree.rowHeight = 80;
    [self.view addSubview:_tableViewThree];
    //传值
    _userDefault2 = [NSUserDefaults standardUserDefaults];
    NSString * intNumber = [NSString stringWithFormat:@"%@",[_userDefault2 valueForKey:@"row2"]];
    int a;
    a = [intNumber intValue ];
//    NSLog( @"----aaaa--%d",a);
    _titleTwoArray = [[NSMutableArray alloc]init];
    [netWork scroll:^(NSArray *arr) {
        [_titleTwoArray setArray:arr];
        
        [_tableViewThree reloadData];
    } type:[NSString stringWithFormat:@"app_loadType?id=%d",a]];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _titleTwoArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//    static NSString *UIimage = @"Identifer";
    //为节省内存，获取之前的存在的tableViewCell
//    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:UIimage];
    UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];
    MAin * main =[_titleTwoArray objectAtIndex:indexPath.row];
    if( cell == nil ){
        //创建UITableViewCell对象，设置行的样式和别名
//        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:UIimage];
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
        cell.selectionStyle=UITableViewCellEditingStyleNone;
        cell.textLabel.text = main.name;
//        NSLog(@"--============--%@",main.name);
        cell.textLabel.font = [UIFont systemFontOfSize:18];
        cell.textLabel.textColor =[UIColor blueColor];
    }
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    TableFourViewController *tableFourView = [[TableFourViewController alloc]init];
    _userDefault3 = [NSUserDefaults standardUserDefaults];
    MAin * main =[_titleTwoArray objectAtIndex:indexPath.row];
    
    NSString * intNumber = [NSString stringWithFormat:@"%@",main.ID];
    NSLog(@"3333333--%@",intNumber);
    [_userDefault3 setValue:intNumber forKey:@"row3"];
    tableFourView.hidesBottomBarWhenPushed = YES;
    tableFourView.myTitle = main.name;
    tableFourView.index = indexPath.row;
    [self.navigationController pushViewController:tableFourView animated:NO];
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
